/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: javase - Img7
 * <p>Powered by webrx On 2021-12-20 17:35:20
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img7 {
    public static void main(String[] args) throws IOException {
        String file = "c:/img.jpg";
        var src = ImageIO.read(new File(file));
        int sw = src.getWidth();
        int sh = src.getHeight();

        //目录图案
        int w = 300;
        int h = 300;

        //按比较 .5
        double sc = .5;
        w = (int) (sw * sc);
        h = (int) (sh * sc);

        //指定宽度，高度按宽的比较计算
        w = 750;
        h = (int) (1.0 * w / sw * sh);
        var dst = new BufferedImage(w, h, 1);
        var g = dst.createGraphics();

        //裁剪图像
        //g.drawImage(src, 0, 0, sw, sh, null);
        //缩略图
        g.drawImage(src, 0, 0, w, h, 0, 0, sw, sh, null);
        g.dispose();

        ImageIO.write(dst, "jpg", new File(String.format("c:/img%d_%d.jpg", w, h)));


    }
}
